package com.example.orderflow.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.example.orderflow.entity.enums.PageSize;
import com.example.orderflow.entity.query.ApprovalStageQuery;
import com.example.orderflow.entity.po.ApprovalStage;
import com.example.orderflow.entity.vo.PaginationResultVO;
import com.example.orderflow.entity.query.SimplePage;
import com.example.orderflow.mappers.ApprovalStageMapper;
import com.example.orderflow.service.ApprovalStageService;
import com.example.orderflow.utils.StringTools;


/**
 *  业务接口实现
 */
@Service("approvalStageService")
public class ApprovalStageServiceImpl implements ApprovalStageService {

	@Resource
	private ApprovalStageMapper<ApprovalStage, ApprovalStageQuery> approvalStageMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<ApprovalStage> findListByParam(ApprovalStageQuery param) {
		return this.approvalStageMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(ApprovalStageQuery param) {
		return this.approvalStageMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<ApprovalStage> findListByPage(ApprovalStageQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<ApprovalStage> list = this.findListByParam(param);
		PaginationResultVO<ApprovalStage> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(ApprovalStage bean) {
		return this.approvalStageMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<ApprovalStage> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.approvalStageMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<ApprovalStage> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.approvalStageMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(ApprovalStage bean, ApprovalStageQuery param) {
		StringTools.checkParam(param);
		return this.approvalStageMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(ApprovalStageQuery param) {
		StringTools.checkParam(param);
		return this.approvalStageMapper.deleteByParam(param);
	}

	/**
	 * 根据ApprovalId获取对象
	 */
	@Override
	public ApprovalStage getApprovalStageByApprovalId(Integer approvalId) {
		return this.approvalStageMapper.selectByApprovalId(approvalId);
	}

	/**
	 * 根据ApprovalId修改
	 */
	@Override
	public Integer updateApprovalStageByApprovalId(ApprovalStage bean, Integer approvalId) {
		return this.approvalStageMapper.updateByApprovalId(bean, approvalId);
	}

	/**
	 * 根据ApprovalId删除
	 */
	@Override
	public Integer deleteApprovalStageByApprovalId(Integer approvalId) {
		return this.approvalStageMapper.deleteByApprovalId(approvalId);
	}

	/**
	 * 根据LevelName获取对象
	 */
	@Override
	public ApprovalStage getApprovalStageByLevelName(String levelName){
		return this.approvalStageMapper.selectByLevelName(levelName);
	};
}